<template>
  <div
    style="width:450px;height:300px"
    ref="chart"
  ></div>
</template>

<script>
// 设备状态视图*******%
import * as echarts from "echarts";
export default {
  mounted() {
    this.initCharts();
  },
  methods: {
    initCharts() {
      let myChart = this.$echarts.init(this.$refs.chart);
      console.log(this.$refs.chart); // 绘制图表
      myChart.setOption({
        xAxis: {
          splitLine: {
            show: false
          },
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          splitLine: {
            show: false
          },
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          }
        },
        series: [
          // 内圆
          {
            type: "pie",
            radius: ["0", "13%"],
            center: ["50%", "46%"],
            // 层级
            z: 4,
            hoverAnimation: false,
            data: [
              {
                name: "积分",
                value: 25,
                itemStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                      {
                        offset: 0,
                        color: "#ae4ecd"
                      },
                      {
                        offset: 1,
                        color: "#ae4ecd"
                      }
                    ])
                  }
                },
                label: {
                  normal: {
                    rich: {
                      a: {
                        // 中心文字颜色
                        color: "#d2a3e2",
                        align: "center",
                        fontSize: 10,
                        //   w文字位置
                        padding: [0, 0, 33, 5],
                        fontWeight: "bold"
                      }
                    },
                    formatter: function(params) {
                      return "{a|" + params.value + "%" + "}\n\n";
                    },
                    position: "center",
                    show: true
                  }
                },
                labelLine: {
                  show: false
                }
              }
            ]
          },
          //进度图
          {
            type: "gauge",
            // 进度大小
            radius: "33%",
            center: ["50%", "46%"],
            min: 0,
            max: 100,
            z: 5,
            splitNumber: 1, //刻度数量
            startAngle: 220, //进度条 从左
            endAngle: -40, //进度条长短 从右
            animation: true,
            animationDuration: 10,
            //分隔线样式。
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            title: {
              show: false
            },
            axisLabel: {
              // 两侧数组距离
              distance: -68,
              color: "#4c72a7",
              fontSize: 12,
              padding: [0, 15, 0, 25],
              formatter: function(value) {
                if (value === 0 || value === 100) {
                  return value + "%";
                }
                return "";
              }
            }, //刻度节点文字颜色
            detail: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                width: 10, //进度条宽度
                // 刻度进度条颜色
                color: [
                  [
                    1,
                    new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                      {
                        offset: 0,
                        color: "rgba(123, 50, 148, 0.4)"
                      },
                      {
                        offset: 1,
                        color: "rgba(59, 42, 154, 1)"
                      }
                    ])
                  ]
                ]
              }
            }
          },
          //刻度尺
          {
            name: "外部刻度",
            type: "gauge",
             center: ['50%', '46%'],
            radius: "35%",
            min: 0, //最小刻度
            max: 10, //最大刻度
            splitNumber: 4, //刻度数量
            // 刻度长度
            startAngle: 219,
            //  刻度起始
            endAngle: -38,
            axisLine: {
              show: false,
              lineStyle: {
                width: 0,
                color: [[1, "rgba(0,0,0,0)"]]
              }
            },
            //仪表盘轴线
            axisLabel: {
              show: false,
              color: "#4d5bd1",
              distance: 25
            }, //刻度标签。
            axisTick: {
              show: true,
              splitNumber: 8,
              lineStyle: {
                color: "#26bbde", //用颜色渐变函数不起作用
                width: 2
              },
              // 小刻度长度
              length: -5
            }, //大刻度样式
            splitLine: {
              show: true,
              length: -0,
              lineStyle: {
                color: "#26bbde" //用颜色渐变函数不起作用
              }
            }, //分隔线样式colorSet
            detail: {
              show: false
            },
            pointer: {
              show: false
            }
          },
          // 外一层圈
          {
            type: "pie",
            radius: "23%",
            startAngle: 220,
            endAngle: -60,
            hoverAnimation: false,
            center: ["50%", "46%"],
            avoidLabelOverlap: false,
            label: {
              show: false
            },
            labelLine: {
              show: false
            },
            data: [
              {
                value: 1
              }
            ],
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 4,
                  colorStops: [
                    {
                      offset: 0,
                      color: "rgba(69, 161, 255,0.8)"
                    },
                    {
                      offset: 1,
                      color: "rgba(69, 161, 255,0.5)"
                    }
                  ]
                }
              }
            }
          },

          //最外层圈
          {
            type: "pie",
            radius: "18%",
            center: ["50%", "46%"],
            avoidLabelOverlap: false,
            z: 0,
            hoverAnimation: false,
            label: {
              show: false
            },
            labelLine: {
              show: false
            },
            data: [
              {
                value: 1
              }
            ],
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 2,
                  colorStops: [
                    {
                      offset: 0,
                      color: "rgba(69, 161, 255,0.3)"
                    },
                    {
                      offset: 1,
                      color: "rgba(69, 161, 255,0.1)"
                    }
                  ]
                }
              }
            }
          }
        ]
      });
    }
  }
};
</script>

<style>
</style>